//
//  AppDelegate.m
//  CarHome
//
//  Created by 王建男 on 14-9-17.
//  Copyright (c) 2014年 WJN_work@163.com. All rights reserved.
//

#import "AppDelegate.h"
#import "DepredateViewController.h"
#import "ForumViewController.h"
#import "RecommendViewController.h"
#import "FindCarViewController.h"

#import "Person_LeftViewController.h"
#import "MMDrawerController.h"

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    _window = nil;
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    
    //左右抽屉
    Person_LeftViewController *person_left = [[Person_LeftViewController alloc] init];
    //降价
    DepredateViewController *depredate = [[DepredateViewController alloc] init];
    
    UIImage *depredate_image_default = [UIImage imageNamed:@"TabBar_Graph.png"];
    depredate_image_default = [depredate_image_default imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *depredate_image_collect = [UIImage imageNamed:@"TabBar_Graph_push.png"];
    depredate_image_collect = [depredate_image_collect imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    depredate.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:depredate_image_default selectedImage:depredate_image_collect];
    [depredate.tabBarItem setImageInsets:UIEdgeInsetsMake(5, 0, -5, 0)];
    
    UINavigationController *depredate_nav = [[UINavigationController alloc] initWithRootViewController:depredate];
    
    //找车
    FindCarViewController *findCar = [[FindCarViewController alloc] init];
    
    UIImage *findCar_image_default = [UIImage imageNamed:@"TabBar_Cars.png"];
    findCar_image_default = [findCar_image_default imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *findCar_image_collect = [UIImage imageNamed:@"TabBar_Cars_push.png"];
    findCar_image_collect = [findCar_image_collect imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    findCar.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:findCar_image_default selectedImage:findCar_image_collect];
    [findCar.tabBarItem setImageInsets:UIEdgeInsetsMake(6, 0, -6, 0)];
    UINavigationController *findCar_nav = [[UINavigationController alloc] initWithRootViewController:findCar];
    
    //论坛
    ForumViewController *forum = [[ForumViewController alloc] init];
    
    UIImage *forum_image_default = [UIImage imageNamed:@"TabBar_Users.png"];
    forum_image_default = [forum_image_default imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *forum_image_collect = [UIImage imageNamed:@"TabBar_Users_push.png"];
    forum_image_collect = [forum_image_collect imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    forum.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:forum_image_default selectedImage:forum_image_collect];
    [forum.tabBarItem setImageInsets:UIEdgeInsetsMake(6, 0, -6, 0)];
    
    UINavigationController *forum_nav = [[UINavigationController alloc] initWithRootViewController:forum];
    
    //推荐
    RecommendViewController *recommend = [[RecommendViewController alloc] init];
    
    UIImage *recommend_image_default = [UIImage imageNamed:@"TabBar_Start.png"];
    recommend_image_default = [recommend_image_default imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *recommend_image_collect = [UIImage imageNamed:@"TabBar_Start_push.png"];
    recommend_image_collect = [recommend_image_collect imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    recommend.tabBarItem = [[UITabBarItem alloc] initWithTitle:nil image:recommend_image_default selectedImage:recommend_image_collect];
    [recommend.tabBarItem setImageInsets:UIEdgeInsetsMake(6, 0, -6, 0)];
    
    UINavigationController *recommend_nav = [[UINavigationController alloc] initWithRootViewController:recommend];
    
    //TabBar
    UITabBarController *car_tabBar = [[UITabBarController alloc] init];
    [car_tabBar setViewControllers:[NSArray arrayWithObjects:recommend_nav, forum_nav, findCar_nav, depredate_nav, nil] animated:NO];
    
    car_tabBar.delegate = self;
    
    [car_tabBar.tabBar setTintColor:[UIColor redColor]]; //tabBartitle color
    
    
    [self.window setRootViewController:car_tabBar];
    

    MMDrawerController *MMD_tabBar = [[MMDrawerController alloc] initWithCenterViewController:car_tabBar leftDrawerViewController:person_left];
    [MMD_tabBar setMaximumLeftDrawerWidth:250.0];
    [MMD_tabBar setOpenDrawerGestureModeMask:MMOpenDrawerGestureModePanningCenterView];
    [MMD_tabBar setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
    [self.window setRootViewController:MMD_tabBar];
    self.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;

    [depredate release];
    [findCar release];
    [forum release];
    [recommend release];
    
    [depredate_nav release];
    [findCar_nav release];
    [forum_nav release];
    [recommend_nav release];
    
    [car_tabBar release];
    
    [person_left release];

    [MMD_tabBar release];
    
    // 设置状态栏字体颜色
    [application setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
    
    [self.window makeKeyAndVisible];
    return YES;
}

#pragma mark -
#pragma tabBar协议
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
